﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Content;

namespace Megaman
{
        class Playlist : System.Collections.ObjectModel.Collection<Song>
        {
            private int nextSong;
            private MediaState previousMediaState;


            public Playlist(ContentManager content)
            {
                // Setup music player
                MediaPlayer.IsRepeating = false;
                MediaPlayer.IsShuffled = false;

                //MediaPlayer.Volume = .25f;

                previousMediaState = MediaState.Playing;
                nextSong = 0;
            }


            public void Play()
            {
                if ((MediaPlayer.State == MediaState.Stopped) && (previousMediaState == MediaState.Playing))
                {

                    Song currentSong = this.Items[nextSong];
                    MediaPlayer.Play(currentSong);

                    if( !MediaPlayer.IsRepeating)

                    nextSong++;

                    if (nextSong > this.Count - 1)
                    {
                        nextSong = 0;
                    }

                }

                previousMediaState = MediaPlayer.State;
            }

            public void AddSong(Song newSong)
            {
                this.Add(newSong);
            }

            public void Stop()
            {
                MediaPlayer.Stop();
            }

            public void Pause()
            {
                MediaPlayer.Pause();
            }

            public void Resume()
            {
                MediaPlayer.Resume();
            }

            public void RepeatTrack(int index)
            {
                MediaPlayer.IsRepeating = true;
            }
            public int songPlaying()
            {
                return nextSong - 1;
            }
        }
    
}
